package com.yourname.www.listen;

import javax.swing.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

public class UsernameTextListener implements KeyListener {
    private JTextField usernameText;
    public UsernameTextListener(JTextField usernameText){
        this.usernameText = usernameText;
    }

    @Override
    public void keyTyped(KeyEvent e) {
        //System.out.println("keyTyped");
       // usernameText.setText(usernameText.getText().trim());
    }
    @Override
    public void keyPressed(KeyEvent e) {

        //usernameText.setText(usernameText.getText().trim());
    }
    @Override
    public void keyReleased(KeyEvent e) {
//        System.out.println("getKeyCode:"+e.getKeyCode());
//        System.out.println("getKeyChar:"+e.getKeyChar());
//        System.out.println("getText:"+usernameText.getText());
          //System.out.println("按键弹起时触发");
        //字符串处理
        usernameText.setText(usernameText.getText().trim());
    }
}
